﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;

namespace DAL3
{
    public static class SQLHelp
    {
        private static string connstring = "server=172.16.150.1;DataBase=MainData;Uid=sa;Pwd=943937821";
        /// <summary>
        /// 按sql读数据库
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static SqlDataReader GetReader(string sql)
        {
            SqlConnection conn = new SqlConnection(connstring);
            SqlCommand cmd = new SqlCommand(sql, conn);
            conn.Open();
            SqlDataReader result = cmd.ExecuteReader();
            // result.Close();
            return result;
        }
        /// <summary>
        /// 按sql增删改数据
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static int AddData(string sql)
        {
            SqlConnection conn = new SqlConnection(connstring);
            SqlCommand cmd = new SqlCommand(sql, conn);
            conn.Open();
            int status = cmd.ExecuteNonQuery();
            conn.Close();
            return status;
        }

    }
}
